package com.xiaoyong.goods.controller;

import com.xiaoyong.entity.Result;
import com.xiaoyong.entity.StatusCode;
import com.xiaoyong.goods.pojo.GoodsDTO;
import com.xiaoyong.goods.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/spu")
public class SpuController {

    @Autowired
    private SpuService spuService;

    /**
     * 新增数据
     * @param goodsDTO
     * @return
     */
    @PostMapping
    public Result add(@RequestBody GoodsDTO goodsDTO){
        spuService.add(goodsDTO);
        return new Result(true, StatusCode.OK,"添加成功");
    }

    /**
     * 根据id查询商品
     * @return
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable String id){
        GoodsDTO goodsById = spuService.findGoodsById(id);
        return new Result(true,StatusCode.OK,"查询成功",goodsById);
    }


    /**
     * 修改成功
     * @param goodsDTO
     * @param id
     * @return
     */
    @PutMapping(value = "/{id}")
    public Result update(@RequestBody GoodsDTO goodsDTO,@PathVariable String id){
        spuService.update(goodsDTO);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /**
     * 审核
     * @param id
     * @return
     */
    @PutMapping("/audit/{id}")
    public Result audit(@PathVariable String id){
        spuService.audit(id);
        return new Result(true,StatusCode.OK,"商品审核成功");
    }

    /**
     * 下架
     * @param id
     * @return
     */
    @PutMapping("/pull/{id}")
    public Result pull(@PathVariable String id){
        spuService.pull(id);
        return new Result(true,StatusCode.OK,"商品下架成功");
    }


    /**
     * 上架商品
     * @return
     */@PutMapping("/put/{id}")
    public Result put(@PathVariable String id){
        spuService.put(id);
        return new Result(true,StatusCode.OK,"商品上架成功");
    }

    /**
     * 恢复数据
     * @return
     */
    @PutMapping("/restore/{id}")
    public Result restore(@PathVariable String id){
        spuService.restore(id);
        return new Result(true,StatusCode.OK,"恢复数据成功");
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        spuService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }
    /**
     * 物理删除
     * @param id
     * @return
     */
    @DeleteMapping("/realDelete/{id}")
    public Result realDelete(@PathVariable String id){
        spuService.realDelete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }
}
